package xyz.liut.ee.error

import jakarta.servlet.ServletException
import jakarta.servlet.annotation.WebServlet
import jakarta.servlet.http.HttpServlet
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import xyz.liut.ee.req.getSimpleReqInfo
import xyz.liut.ee.req.printReq
import xyz.liut.ee.resp.ResponseEntity
import xyz.liut.ee.resp.sendBy
import java.io.IOException

@WebServlet(name = "Error", urlPatterns = ["/ErrorHandler"])
class ErrorHandlerServlet : HttpServlet() {
    @Throws(ServletException::class, IOException::class)
    override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
        super.doGet(req, resp)
        doPost(req, resp)
    }

    @Throws(ServletException::class, IOException::class)
    override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
        super.doPost(req, resp)
        req.printReq()

        ResponseEntity(200, "出错", req.getSimpleReqInfo()).sendBy(resp)
    }
}
